console.log("Switch Statement Test Start");

let value = 2;

switch (value) {
  case 1:
    console.log("Value is 1");
    break;
  case 2:
    console.log("Value is 2");
    break;
  case 3:
    console.log("Value is 3");
    break;
  default:
    console.log("Value is not 1, 2 or 3");
}

// Test fallthrough behavior
console.log("\nTesting fallthrough behavior:");
switch (value) {
  case 1:
    console.log("Value is 1");
  case 2:
    console.log("Value is 2"); // This should execute
  case 3:
    console.log("Value is 3"); // This should also execute because there's no break above
    break;
  default:
    console.log("Value is not 1, 2 or 3");
}

// Test expressions in case clauses
console.log("\nTesting expressions in case clauses:");
switch (value) {
  case 1 + 1: // Expression that evaluates to 2
    console.log("Expression 1+1 matches value 2");
    break;
  case 5 - 2: // Another expression that evaluates to 3
    console.log("Expression 5-2 matches");
    break;
  default:
    console.log("No expressions matched");
}

// Test multiple cases sharing the same code block
console.log("\nTesting multiple cases sharing the same code block:");
let fruit = "apple";
switch (fruit) {
  case "apple":
  case "pear":
  case "banana":
    console.log("This is a fruit");
    break;
  case "carrot":
  case "potato":
    console.log("This is a vegetable");
    break;
  default:
    console.log("Unknown food type");
}

// Test switch with different types
console.log("\nTesting switch with different types:");

// 首先测试数字
console.log("Testing number 1:");
switch (1) {
  case 1:
    console.log("  Number 1 matched");
    break;
  default:
    console.log("  No match found");
}

// 测试字符串
console.log("Testing string 'true':");
switch ("true") {
  case "true":
    console.log("  String 'true' matched");
    break;
  case true:
    console.log("  Boolean true matched");
    break;
  default:
    console.log("  No match found");
}

// 测试布尔值
console.log("Testing boolean true:");
switch (true) {
  case 1:
    console.log("  Number 1 matched");
    break;
  case "true":
    console.log("  String 'true' matched");
    break;
  case true:
    console.log("  Boolean true matched");
    break;
  default:
    console.log("  No match found");
}

// 测试null
console.log("Testing null:");
switch (null) {
  case null:
    console.log("  Null matched");
    break;
  default:
    console.log("  No match found");
}

// 测试无匹配
console.log("Testing no match:");
console.log("  Before switch");
switch ("other") {
  case 1:
    console.log("  Number matched");
    break;
  case "true":
    console.log("  String matched");
    break;
  case true:
    console.log("  Boolean matched");
    break;
  case null:
    console.log("  Null matched");
    break;
  default:
    console.log("  No match found");
}
console.log("  After switch");

// Test default in different positions
console.log("\nTesting default in different positions:");
let num = 10;
switch (num) {
  default:
    console.log("This is the default case (at the beginning)");
    break;
  case 5:
    console.log("Case 5 matched");
    break;
  case 10:
    console.log("Case 10 matched");
    break;
}

// Test nested switch statements
console.log("\nTesting nested switch statements:");
let outer = 1;
let inner = 2;
switch (outer) {
  case 1:
    console.log("Outer case 1");
    switch (inner) {
      case 1:
        console.log("Inner case 1");
        break;
      case 2:
        console.log("Inner case 2");
        break;
      default:
        console.log("Inner default");
    }
    break;
  case 2:
    console.log("Outer case 2");
    break;
  default:
    console.log("Outer default");
}

// Test switch with return values (if inside a function)
console.log("\nTesting switch with return values:");
function testSwitchReturn(val) {
  switch (val) {
    case 1:
      return "One";
    case 2:
      return "Two";
    case 3:
      return "Three";
    default:
      return "Unknown";
  }
}
console.log("Return value:", testSwitchReturn(2));
console.log("Return value:", testSwitchReturn(5));

console.log("\nSwitch Statement Test End");



~function bbb(){
  console.log("ok")
}

bbb()



